<?php
/**
 * Notes:
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/10/4
 * Time: 13:38
 */

namespace app\index\controller;
use app\model\MapArea;
use app\model\MapCity;
use app\model\MapProvince;
use think\Validate;

class Util
{
    public function uploadImg(){

        // 获取表单上传文件
        $file = request()->file('image');
        // 进行验证与重命名最后移动到 public/uploads 目录下
        $info = $file->validate(['size'=>1024*1024*2,'ext'=>'jpg,png,gif'])->rule('date')->move(ROOT_PATH . 'public' . DS . 'uploads' . DS . 'img');
        if($info){
            // 成功上传后 获取上传信息
            $filename = ["file_name" => $info->getSaveName()];
            $filename = 'http://contact.yhong.info/uploads/img/' . $filename["file_name"];
            return res(1,'上传成功',[
                "imgUrl" => $filename
            ]);
        }else{
            return res(0,$file->getError());
        }
    }
    public function getAddress(){
        $MapModel = new MapArea();
        $all_address = $MapModel->getByArea();
        return res(1,'',$all_address);
    }

    public function getProvince(){
        $MapProvince = new MapProvince();
        $all_province = $MapProvince->getProvince();
        return res(1,'',$all_province);
    }

    public function getCity(){
        $province_id = input('province_id');
        if(!checkNull($province_id)) return res(0,MSG_NOT_KEY);
        $MapCity = new MapCity();
        $select_city = $MapCity->getCity($province_id);
        return res(1,'',$select_city);
    }
    public function getUserAddress(){
        $area_id = input('area_id');
        if(!checkNull($area_id)) return res(0,MSG_NOT_KEY);
        $MapArea = new MapArea();
        $user_address = $MapArea->getByAreaId($area_id);
        return res(1,'',$user_address);
    }
    public function getArea(){
        $city_id = input('city_id');
        if(!checkNull($city_id)) return res(0,MSG_NOT_KEY);
        $MapArea = new MapArea();
        $select_area = $MapArea->getArea($city_id);
        return res(1,'',$select_area);
    }


}